package com.asset.inventory.view

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment
import com.asset.inventory.R
import com.asset.inventory.constant.InventoryState

/**
 *    @author : sibb
 *    date   : 21-4-12
 *    desc   : 修改盘点状态的对话框
 */
class ModifyStateDialog(val position: Int, val lisener: onStateSelectedListener): DialogFragment() {

    interface onStateSelectedListener{
        fun onChange(position: Int,state: String)
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val view = inflater.inflate(R.layout.dialog_modify_state, container, false)
        val waitInventory: TextView = view.findViewById(R.id.waitInventory)
        val equality: TextView = view.findViewById(R.id.equality)
        val loss: TextView = view.findViewById(R.id.loss)
        waitInventory.setOnClickListener {
            lisener.onChange(position,InventoryState.STATE_WAIT)
            dismiss()
        }

        equality.setOnClickListener {
            lisener.onChange(position,InventoryState.STATE_EQUALITY)
            dismiss()
        }

        loss.setOnClickListener {
            lisener.onChange(position,InventoryState.STATE_LOSS)
            dismiss()
        }
        return view
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initWindow()
        initView()
    }

    private fun initView() {

    }

    private fun initWindow() {
        //初始化window相关表现
        val window = dialog?.window
        //设备背景为透明（默认白色）
        window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        //设置window宽高(单位px)
        window?.attributes?.width = 700
        window?.attributes?.height = 350
        //设置window位置
        window?.attributes?.gravity = Gravity.CENTER//居中
    }
}